package com.bjpowernode.listener;

import com.bjpowernode.pojo.ProductType;
import com.bjpowernode.service.impl.ProductTypeServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

@WebListener
public class ProductTypeListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext_*.xml");
        ProductTypeServiceImpl productTypeServiceImpl = context.getBean("productTypeServiceImpl", ProductTypeServiceImpl.class);
        List<ProductType> all = productTypeServiceImpl.getAll();
        servletContextEvent.getServletContext().setAttribute("typeList",all);

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
